package com.biz.primus.ms.commodity.dao.repository.product;

import com.biz.primus.commodity.enums.ProductAuditStatus;
import com.biz.primus.ms.base.jpa.repository.CommonJpaRepository;
import com.biz.primus.ms.commodity.dao.po.ProductAudit;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 商品审核记录 Repository
 *
 * @author david-liu
 * @date 2016年12月23日
 * @reviewer
 * @see
 */
public interface ProductAuditRepository extends CommonJpaRepository<ProductAudit, Long>, ProductAuditDao,JpaSpecificationExecutor<ProductAudit> {

    ProductAudit findByProductIdAndDeleteFlag(Long productId, Boolean deleteFlag);

    Page<ProductAudit> findByAuditStatusNotAndDeleteFlag(ProductAuditStatus productAuditStatus,
                                                         Boolean deleteFlag, Pageable pageable);

    @Query("FROM ProductAudit p WHERE p.vendorId = ?1 AND p.category.id = ?2 AND p.deleteFlag = ?3")
    Page<ProductAudit> findByVendorIdAndCategoryIdAndDeleteFlag(Long vendorId, Long categoryId, Boolean deleteFlag, Pageable pageable);

    Page<ProductAudit> findByVendorIdAndDeleteFlag(Long vendorId, Boolean deleteFlag, Pageable pageable);

    @Query("FROM ProductAudit p WHERE p.category.id = ?1 AND p.deleteFlag = ?2")
    Page<ProductAudit> findByCategoryIdAndDeleteFlag(Long categoryId, Boolean deleteFlag, Pageable pageable);

    Page<ProductAudit> findByDeleteFlag(Boolean deleteFlag, Pageable pageable);

    ProductAudit findByProductIdAndVendorIdAndDeleteFlag(Long productId, Long vendorId, Boolean deleteFlag);

    ProductAudit findByIdAndDeleteFlag(Long id, Boolean deleteFlag);

    List<ProductAudit> findByProductCodeAndVendorId(String productCode, Long vendorId);

    ProductAudit findByProductId(Long id);
}
